/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.isip.edgeDetection;

import com.azon.ip.utils.Matrix3x3;
import com.isip.transformation.difference.MatrixTransformation;

/**
 *
 * @author Ahmad Fauzan
 */
public class FreiChen2EdgeDetection implements EdgeDetection{

    @Override
    public int[][] detect(int[][] matrixImage) {
        float[] matrixConv1 = {1,0,-1,
                                (float)Math.sqrt(2),0,-(float)Math.sqrt(2),
                                1,0,-1};
        Matrix3x3 matrix = new Matrix3x3(matrixConv1);
        int[][] tempImage1,tempImage2;
        MatrixTransformation t1 = new MatrixTransformation();
        t1.setMatrixTransformation(matrix.getMatrixArray());
        tempImage1 = t1.doTransform(matrixImage);
        System.out.println(matrix);
        for(int i=0; i < 7; i++) {
            matrix.rotate45();
            System.out.println(matrix);
            t1.setMatrixTransformation(matrix.getMatrixArray());
            tempImage2 = t1.doTransform(matrixImage);
            tempImage1 = sum(tempImage1, tempImage2);
        }
        return tempImage1;
    }
    
    private int[][] sum(int[][] matrix1, int[][] matrix2) {
        int[][] temp = new int[matrix1.length][matrix1[0].length];
        for(int i=0; i < matrix1.length; i ++) {
            for(int j=0; j < matrix1[i].length;j++) {
                temp[i][j] = (int)Math.sqrt(matrix1[i][j]*matrix1[i][j] + matrix2[i][j]*matrix2[i][j]);
            }
        }
        return temp;
    }
}
